import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

import com.google.code.ptrends.Application.DAL.SearchServiceBean;
import com.google.code.ptrends.Application.DAL.entities.CategoryEntity;
import com.google.code.ptrends.Application.DAL.entities.ItemEntity;
import com.google.code.ptrends.Application.DAL.entities.ManufacturerEntity;
import com.google.code.ptrends.Application.DAL.entities.SupplierEntity;

@ManagedBean(name = "search")
@ViewScoped
public class SearchBean implements Serializable{
	
	private static final long serialVersionUID = 1L;

	@EJB
	transient SearchServiceBean beanSearch;
	
	private List<ManufacturerEntity> manufacturer;
	private ManufacturerEntity manufactSelected;
	
	private List<SupplierEntity> supplier;
	private SupplierEntity supplierSelected;
	
	private List<CategoryEntity> category;
	private CategoryEntity categorySelected;
	
	private String id;
	private String model;
	
	private List<ItemEntity> item  = new ArrayList<ItemEntity>();
	
	public List<ItemEntity> getItem() {
		item = beanSearch.getAllItem();
		return item;
	}

	public SearchBean() {
		id = "";
		model = "";
	}

	public void setManufacturer(List<ManufacturerEntity> manufacturer) {
		this.manufacturer = manufacturer;
	}

	public List<ManufacturerEntity> getManufacturer() {
		loadData();
		return manufacturer;
	}
	
	private void loadData() {
		if (manufacturer == null)
			manufacturer = beanSearch.getAllManufacturer();
		if (supplier == null)
			supplier = beanSearch.getAllSupplier();
		if (category == null) 
			category = beanSearch.getAllCategory();
	}

	public void setManufactSelected(ManufacturerEntity manufactSelected) {
		this.manufactSelected = manufactSelected;
	}

	public ManufacturerEntity getManufactSelected() {
		return manufactSelected;
	}

	public void setSupplier(List<SupplierEntity> supplier) {
		this.supplier = supplier;
	}

	public List<SupplierEntity> getSupplier() {
		loadData();
		return supplier;
	}

	public void setSupplierSelected(SupplierEntity supplierSelected) {
		this.supplierSelected = supplierSelected;
	}

	public SupplierEntity getSupplierSelected() {
		return supplierSelected;
	}

	public void setCategorySelected(CategoryEntity categorySelected) {
		this.categorySelected = categorySelected;
	}

	public CategoryEntity getCategorySelected() {
		return categorySelected;
	}

	public List<CategoryEntity> getCategory() {
		return category;
	}

	public void setCategory(List<CategoryEntity> category) {
		loadData();
		this.category = category;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getModel() {
		return model;
	}

	public void search(ActionEvent action) {
		
	}

}
